<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<%@page import="com.liferay.portal.kernel.util.StringPool"%>
<%@ include file="/html/init.jsp"%>

<portlet:actionURL windowState="<%=LiferayWindowState.NORMAL.toString()%>" name="savepopup" var="savepopupURL" />
<%
	List<Country> countries = CountryServiceUtil.getCountries();
	List<Region> regions = RegionServiceUtil.getRegions();
	List<City> cities = CityLocalServiceUtil.getCities(0, -1);
%>

<aui:form action="<%=savepopupURL%>" name="fm" method="POST">
	<aui:field-wrapper cssClass="registration">
		<aui:column cssClass="aui-w40">
			<aui:select name="countryId" onchange="getRegions();" label="Country">
				<aui:option value="">--Select--</aui:option>
				<%
					for (Country country : countries) {
				%>
				<aui:option value="<%=country.getCountryId()%>" selected="<%=(country.getCountryId() == location.getCountryId()) ? true : false%>"> <%=country.getName()%> </aui:option>
				<%
					}
				%>
			</aui:select>

			<aui:select name="regionId" onchange="getCities();" label="Region/State">
				<aui:option value="">--Select--</aui:option>
				<%
					regions = RegionServiceUtil.getRegions(location.getCountryId());
					for (Region region : regions) {
				%>
				<aui:option value="<%=region.getRegionId()%>" selected="<%=(region.getRegionId() == location.getRegionId()) ? true : false%>"><%=region.getName()%> </aui:option>
				<%
					}
				%>
			</aui:select>

			<%
				cities = CityLocalServiceUtil.getRegion_Cities(location.getRegionId());
			%>
			<aui:fieldset id="cities">
				<aui:select name="city" label="City">
					<aui:option value="">--Select--</aui:option>
					<%
						for (City city : cities) {
					%>
					<aui:option value="<%=city.getCityId()%>" selected="<%=(city.getCityId() == location.getCityId()) ? true : false%>"> <%=city.getCityName()%></aui:option>
					<%
						}
					%>
				</aui:select>
			</aui:fieldset>
			<aui:fieldset id="otherCity">
				<aui:input name="otherCity" type="text" value="<%=location.getCity()%>" label="Enter New City :" />
			</aui:fieldset>

			<aui:input type="hidden" name="addressId"
				value="<%=location.getAddressId()%>" />
		</aui:column>
	</aui:field-wrapper>

	<aui:button-row>
		<aui:button type="submit" value="Save" />
	</aui:button-row>

</aui:form>

<aui:script>
	AUI().use('aui-io-request', function(A){
		
		A.one("#<portlet:namespace />"+"otherCity").hide();
	   
	});
</aui:script>
